﻿--HEADER Change Trade Price column to NULL
IF OBJECT_ID ('[TradingData].[JoinedTrade]', 'V') IS NOT NULL
DROP VIEW [TradingData].[JoinedTrade] ;

GO

ALTER TABLE [TradingData].[Trade]
	 ALTER COLUMN Price money NULL

GO

CREATE VIEW [TradingData].[JoinedTrade]
WITH SCHEMABINDING
AS
SELECT     t.FundBookEntityId, t.SecurityId, t.Id, t.Quantity, t.Date, t.CurrencyId, t.Price, t.FxRate, bs2b.BenchmarkId
FROM         TradingData.Trade AS t INNER JOIN
                      TradingData.BookSecurityToBenchmark AS bs2b ON t.FundBookEntityId = bs2b.FundBookEntityId AND t.SecurityId = bs2b.SecurityId INNER JOIN
                         TradingData.Security AS s ON t.SecurityId = s.Id INNER JOIN
                         TradingData.SecurityClass AS sc ON s.ClassId = sc.Id
WHERE        (sc.Include = 1)
GO
CREATE UNIQUE CLUSTERED INDEX [JoinedTradeIndex]
    ON [TradingData].[JoinedTrade]([Id] ASC);